package com.tedu.pojo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.User;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

@Controller
public class UserController {

    @RequestMapping("/paser01")
    @ResponseBody   //  直接返回文本数据，不需要进行视图解析器
    public String paser01(HttpServletRequest request){
        return request.getParameter("name");
    }

    @RequestMapping("/paser02")
    @ResponseBody
    public String paser02( @RequestParam(value = "name",required = true)  String name, String password){
        String  pam = "用户名："+ name +"; 密码："+ password;
        System.out.println(pam);
        return pam ;
    }

    @RequestMapping("/login")
    @ResponseBody
    public String login(User user) throws UnsupportedEncodingException {
        String name = new String(user.getUsername().getBytes("iso8859-1"),"utf-8");
        user.setUsername(name);
        System.out.println(user);
        return user.toString();
    }
}
